#include "aki/jsbind.h"


/**
 * @brief: 全局函数类型为：aki::ArrayBuffer (*)(aki::ArrayBuffer)
 * @result: passed
 */
void PassingArrayBufferReturnVoid(aki::ArrayBuffer origin) {

    int8_t* data = reinterpret_cast<int8_t *>(origin.GetData());
    data[4] = 4;
    data[5] = 5;
    data[6] = 6;
    data[7] = 7;

    return;
}

/**
 * @brief: 全局函数类型为：aki::ArrayBuffer (*)(aki::ArrayBuffer)
 * @result: passed
 */
aki::ArrayBuffer PassingArrayBufferReturnArrayBuffer(aki::ArrayBuffer origin) {
    aki::ArrayBuffer buff(origin.GetData(), origin.GetCount());
    uint8_t* data = buff.GetData();
    data[4] = 4;
    data[5] = 5;
    data[6] = 6;
    data[7] = 7;

    return buff;
}

/**
 * @brief: 全局函数类型为：aki::ArrayBuffer (*)(aki::ArrayBuffer)
 * @result: passed
 */
aki::ArrayBuffer PassingArrayBufferReturnInt8Array(aki::ArrayBuffer origin) {
    aki::ArrayBuffer buff(origin.GetData(), origin.GetCount(), aki::ArrayBuffer::INT8);
    int8_t* data = reinterpret_cast<int8_t*>(buff.GetData());
    data[4] = -4;
    data[5] = -5;
    data[6] = -6;
    data[7] = -7;

    return buff;
}

/**
 * @brief: 全局函数类型为：aki::ArrayBuffer (*)(aki::ArrayBuffer)
 * @result: passed
 */
aki::ArrayBuffer PassingArrayBufferReturnInt16Array(aki::ArrayBuffer origin) {
    aki::ArrayBuffer buff(origin.GetData(), origin.GetCount(), aki::ArrayBuffer::INT16);
    int16_t* data = reinterpret_cast<int16_t*>(buff.GetData());
    data[4] = -40;
    data[5] = -50;
    data[6] = -60;
    data[7] = -70;

    return buff;
}

JSBIND_ADDON(arraybuffer2native)
JSBIND_GLOBAL() {
    JSBIND_FUNCTION(PassingArrayBufferReturnVoid);
    JSBIND_FUNCTION(PassingArrayBufferReturnArrayBuffer);
    JSBIND_FUNCTION(PassingArrayBufferReturnInt8Array);
    JSBIND_FUNCTION(PassingArrayBufferReturnInt16Array);
}